<template>
  <c-form-dialog
    ref="form"
    :visible.sync="innerVisible"
    :form-items="formItems"
    :form-data="formData"
    :table-name="tableName"
    :table-id="tableId"
    @close="handleClose"
    @success="handleSuccess"
    :before-save="handleBeforeSave"
  ></c-form-dialog>
</template>

<script>
export default {
  components: {},
  props: {
    visible: Boolean,
    tableId: String,
    formData: {
      type: Object,
      default() {
        return {}
      },
    },
  },
  data() {
    return {
      innerVisible: false,
      tableName: 'customer_related',
      formItems: [
        {
          tag: 'input',
          itemAttrs: {
            label: '申请金额',
            rules: [{ required: true, message: '请输入申请金额', trigger: 'blur' }],
          },
          attrs: { key: 'apply_funds', value: '', placeholder: '请输入申请金额' },
          tagSlots: [{ name: 'append', slot: '万元' }],
          directives: [
            {
              name: 'input-number',
              value: {
                min: 0,
                fixed: 2,
              },
            },
          ],
        },
        {
          tag: 'number',
          itemAttrs: {
            label: '贷款期限',
            rules: [{ required: true, message: '请填写贷款期限', trigger: 'blur' }],
          },
          attrs: { key: 'months', value: '' },
          tagSlots: [{ name: 'append', slot: '月' }],
          directives: [
            {
              name: 'input-number',
              value: {
                min: 0,
                fixed: 2,
              },
            },
          ],
        },
        {
          tag: 'input',
          itemAttrs: {
            label: '贷款用途',
            rules: [{ required: true, message: '请输入贷款用途', trigger: 'blur' }],
          },
          attrs: { clearable: false, key: 'funds_use_dir', placeholder: '请输入贷款用途' },
        },
      ],
    }
  },
  computed: {},
  watch: {
    visible(val) {
      this.innerVisible = val
    },
  },
  created() {},
  mounted() {},
  methods: {
    handleBeforeSave(model) {
      return model
    },
    handleClose() {
      this.$emit('update:visible', false)
    },
    handleSuccess(res) {
      this.$emit('success', res)
    },
  },
}
</script>
<style lang="scss" scoped></style>
